package com.mi.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.mi.entity.MyPages;
import com.mi.entity.NewsEntity;
import com.mi.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;


@Controller
public class NewsController {

    @Reference(check = false)
    NewsService newsService;


    //跳到查询新闻的方法
    @RequestMapping("jumpnews")
    public  String jumpNews(){
        return "redirect:queryNews";
    }



//
//    //跳到查询首页查询新闻的方法
//    @RequestMapping("jumpindexnews")
//    public  String jumpIndexNews(){
//        return "redirect:jumptoindexnew";
//    }

    @RequestMapping("jumppartner")
    public String jumpPartner(){
        return "partner";
    }

    //根据新闻名模糊查询
    @RequestMapping("fuzzy")
    public String fuzzyQuery(NewsEntity ne,HttpServletRequest request){

        MyPages<NewsEntity> news = newsService.fuzzyQuery(ne);

        request.setAttribute("news",news);
        request.setAttribute("name",ne.getN_name());

        return "search";

    }


    /**
     *
     * @param newsEntity
     * @param request
     * @return
     */
    @RequestMapping("queryNews")
    public String queryNewsInfo(NewsEntity newsEntity, HttpServletRequest request){

        MyPages<NewsEntity> newsEntities = newsService.queryNews(newsEntity);

        request.setAttribute("catid",newsEntity.getN_category());
        request.setAttribute("listinfo",newsEntities);
        return "News";
    }

    //查询信息
    @RequestMapping("queryNewsDetail")
    public String queryNewsDetail(NewsEntity newsEntity, HttpServletRequest request){
        int n_id=newsEntity.getN_id();
        System.out.println("获取到的id是："+n_id);

//        if (("".equals(n_id))){
//            return "News";
//        }
        NewsEntity news = newsService.queryDetails(n_id);
        String n_desc = news.getN_desc();
//        System.out.println("该路径为："+n_desc);
//        System.out.println("信息ID为："+n_id+" 信息为："+news);
        request.setAttribute("news",news);
        return "News_info";
    }

}
